# -*- coding: utf-8 -*-
__author__ = 'zengao'
__email__ = '1759073141@qq.com'
"""
缓存类
"""
from collections import UserDict


class CachePool(UserDict):
    """全局变量池"""

    def get(self, key, default=None):
        return self.data.get(key, default)

    def set(self, key, value = None):
        self.data.setdefault(key, value)

    def has(self, key):
        return key in self.data

    def __len__(self):
        return len(self.data)

    def __bool__(self):
        return bool(self.data)


cache = CachePool()

if __name__ == '__main__':
    cache.set('name', 'wxhou')
    print(len(cache))
    print(cache.get('name'))